package com.youfang.sixthmedia.calc;

import java.io.Serializable;
import java.util.ArrayList;

public class YoufangCalc {

	// 等额本息计算结果
	public static class DEBX implements Serializable {

		public double loanCount;
		public double paymentCount;
		public double loanInterest;
		public double monthTotal;
		public double averagePayment;

		public DEBX calc(double count, double rate, int month) {

			count = count * 10000;
			rate = rate / 1000;

			double average = count * (rate * Math.pow((rate + 1), month))
					/ (Math.pow(rate + 1, month) - 1);

			loanCount = count / 10000;
			paymentCount = (average * month) / 10000;
			loanInterest = (average * month - count) / 10000;
			monthTotal = month;
			averagePayment = average;
			return this;

		}

	}

	// 等额本金计算结果
	public static class DEBJ implements Serializable {
		ArrayList<String> payList;

		double loanCount;
		double paymentCount;
		double loanInterest;
		double monthTotal;

		public DEBJ calc(double count, double rate, int month) {

			count = count * 10000;
			rate = rate / 1000;

			double average = count / month;
			float ct = 0;

			// 每月还款额
			payList = new ArrayList<String>();
			for (int i = 0; i < month; i++) {
				double intrest = (count - i * average) * rate;
				payList.add(String.valueOf(average + intrest));
				ct += (average + intrest);
			}

			loanCount = count / 10000;
			paymentCount = ct / 10000;
			loanInterest = (ct - count) / 10000;
			monthTotal = month;

			return this;

		}

	}

}
